<template>
	<view class="header">
		<myHead :title="title" />
		
		<view class="main">
			<uni-grid :column="3" borderColor="#ffffff"  :highlight="false">
			    <uni-grid-item v-if="hashIndex['1']!==undefined">
			       <view @tap="pageTo(menuMap[hashIndex['1']].menuChild,true)">
					   <image src="../../static/party_building/assets/footprint3x.png" mode=""></image>
					   <p>党支部</p>
				   </view>
			    </uni-grid-item>
			    <!-- <uni-grid-item v-if="hashIndex['2']!==undefined"> -->
			    <uni-grid-item>
			       <view @tap="pageTo('/pages/discipline/index',false)">
					   <image src="../../static/party_building/assets/collection3x.png" mode=""></image>
					   <p>纪检</p>
				   </view>
			    </uni-grid-item>
			    <uni-grid-item  v-if="hashIndex['3']!==undefined">
			       <view @tap="pageTo(menuMap[hashIndex['3']].menuChild,true)">
					   <image src="../../static/party_building/assets/handbook.png" mode=""></image>
					   <p>工会</p>
				   </view>
			    </uni-grid-item>
			    <uni-grid-item  v-if="hashIndex['4']!==undefined">
			       <view @tap="pageTo(menuMap[hashIndex['4']].menuChild,true)">
					   <image src="../../static/party_building/assets/grouping3x.png" mode=""></image>
					   <p>团支部</p>
				   </view>
			    </uni-grid-item>
			    <uni-grid-item  v-if="hashIndex['5']!==undefined">
			       <view  @tap="pageTo(menuMap[hashIndex['5']].menuChild,true)">
					   <image src="../../static/party_building/assets/draft3x.png" mode=""></image>
					   <p>妇联</p>
				   </view>
			    </uni-grid-item>
				
			</uni-grid>
		</view>
	</view>
</template>

<script>
	import myHeader from '../components/head.vue'
	export default {
		data(){
			return {
				title:"请选择部门",
				menuMap:[],
				hashIndex:{},
				
			}
		},components:{
				myHead:myHeader,
			},
			mounted() {
				let _this = this
				uni.getStorage({
				    key: 'user',
				    success: function (res) {
						console.log("user",res)
				        _this.user = res.data.user;
				    }
				});
				// uni.getStorage({
				//     key: 'menuMap',
				//     success: function (res) {
				//         _this.menuMap = res.data;
				//     }
				// });
				 _this.menuMap = uni.getStorageSync("menuMap")
					_this.hashIndex = {},
					_this.menuMap.forEach((item,index)=>{//形成 departId，index，映射
						_this.hashIndex[item.departId] = index
					})
					console.log(this.menuMap,this.hashIndex)
			},
		methods: {
			pageTo(val,isMenuChild){//（跳转菜单，是否有子菜单）
				if(isMenuChild){
				uni.navigateTo({
					url:`../components/loadBuilding?param=${JSON.stringify(val)}`
					})	
				}else{
				uni.navigateTo({
					url:val
					})	
				}
			}
		},
	}
</script>
<style lang="scss" scoped>	
.header{
	.main{
		border-radius: 2%;
		overflow: hidden;
		width: 95%;
		min-height: 11.68rem;
		max-height: 53%;
		background: #fff;
		margin: 105upx auto 0;
		/deep/ .uni-grid-wrap{
			.uni-grid-item{
				height: 80upx;
				.uni-grid-item__box {
					position: relative;
					top: 25%;
					left:25%;
					>uni-view{
					    width: 50%;
					    text-align: center
					}
					image{
						width: 35px;
						height: 33px;
						// width: 40px;
						// height: 36px;
					}
				}
			}
		}
	}
}
</style>